package com.muqi.app.qlearn.adapter;

import java.util.List;

import com.easemob.easeui.widget.CircularImage;
import com.muqi.app.network.http.GlideImageUtils;
import com.muqi.app.qlearn.student.R;
import com.muqi.app.user.db.MyClassStudent;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
/**
 * 可勾选user 头像选择adapter
 * @author wenhui
 *
 */
public class AvatarSelectAdapter extends BaseAdapter {
	private Context context;
	private List<MyClassStudent> listData;

	public AvatarSelectAdapter(Context context, List<MyClassStudent> listData) {
		this.context = context;
		this.listData = listData;
	}

	@Override
	public int getCount() {
		return listData == null ? 10 : listData.size();
	}

	@Override
	public MyClassStudent getItem(int position) {
		return listData.get(position);
	}
   
	@Override
	public long getItemId(int position) {
		return position;
	}

	@SuppressLint("InflateParams") @Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		final MyClassStudent itemInfo = listData.get(position);
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(R.layout.item_user_avatar2, null);
			holder.itemAvatar = (CircularImage) convertView.findViewById(R.id.mCircularImage);
			holder.itemName = (TextView) convertView.findViewById(R.id.mUserName);
			holder.isChecked = (ImageView) convertView.findViewById(R.id.mChecked);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		GlideImageUtils.setImageLoader(context, itemInfo.student_avatar, 
					holder.itemAvatar, R.drawable.default_avator);
		holder.itemName.setText(itemInfo.student_name+"");
		
		if(itemInfo.isChecked){
			holder.isChecked.setVisibility(View.VISIBLE);
			//holder.isChecked.setImageResource(R.drawable.icon_avatar_check_true);
		}else{
			holder.isChecked.setVisibility(View.GONE);
			//holder.isChecked.setImageResource(R.drawable.icon_avatar_check_false);
		}
		return convertView;
	}
	
	private class ViewHolder {
		CircularImage itemAvatar;
		TextView itemName;
		ImageView isChecked;
	}
}
